<template>
	<view class="father">
		<view class="b1">
			<view class="bt">
				<view class="b1_1" v-if="totalmoney != null">
					总盈收:{{totalmoney}}
				</view>
				<view class="b1_1" v-else>
					暂无数据
				</view>
				<view class="b1_zz">(计算今年所盈利的总和)</view>
			</view>

			<view class="b1_2">
				<button class="b1_2_1" @click="yijie()">已结清</button>
			</view>
			<view class="b1_3">
				<button class="b1_3_1" @click="weijie()">未结清</button>
			</view>
		</view>

		<view class="bb" v-if="shops.length !=0 ">
			<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scrolltoupper="upper"
				@scrolltolower="lower" @scroll="scroll">
				<view v-for="item in shops" class="b2" @click="tt(item.shopname)">
					<view class="b2_1">
						<view>门店名:{{item.shopname}}</view>
						<view>门店地址:{{ truncateAddress(item.address) }}</view>
					</view>
					<view class="b2_2">
						
						<view v-if="item.profit != null">已盈收: {{item.profit}}元</view>
						<view v-else>已盈收:0元</view>
						<view class="ss" v-if="item.pay==0">
							<text style="font-size: 25rpx; ">已结清</text>
						</view>
						<view class="ee" v-else>
							<text style="font-size: 25rpx;">未结清</text>
						</view>


					</view>
				</view>
			</scroll-view>
		</view>
		<view class="aa" v-else >
			<view>暂无数据</view>
		</view>

	</view>
	<tabBar></tabBar>
</template>

<script setup>
	import {
		ref,
		onMounted
	} from 'vue'
	import {http} from '/until/request.js'
	const pay01 = ref(0)
	const pay02 = ref(1)

	const sname = ref("");

	// 点击门店模块
	const tt = (shopname) => {
		sname.value = shopname; //对象赋值
		uni.navigateTo({
			url: `/pages/supplier/bill/billdetails?sname=${encodeURIComponent(sname.value)}`
		});
	};


	// 截断地址
	const truncateAddress = (address) => {
		if (address.length > 10 && address.length != null) {
			return address.slice(0, 8) + '...';
		}
		return address;
	};
	
	
	//总价
	const totalmoney = ref(0)
	//商家数据模型
	const shops = ref([])
	//备份数据模型
	const shops2 = ref([])
	const shopsyj = ref([])
	
	const chaxun = async () => {
		const res = await http({
			url: '/orders/selectall',
			method: 'get'
		})
		shops.value = res.data.auditVOList
		shops2.value = res.data.auditVOList
		totalmoney.value = res.data.sum;
		console.log("账单数据模型")
		console.log(res.data)
	}
	
	//已结算按钮
	const yijie = () => {
		const pay = shops2.value
		shopsyj.value = pay.filter(item => pay01.value == item.pay);
		shops.value = shopsyj.value
	}

	//未结算按钮
	const weijie = () => {
		const pay = shops2.value
		shopsyj.value = pay.filter(item => pay02.value == item.pay);
		shops.value = shopsyj.value
	}

	onMounted(() => {
		chaxun();
	});
</script>
<style lang="scss">
	.father {
		width: 100%;
		height: 100vh;
		// border: 1px solid rebeccapurple;
		font-size: 40rpx;
		display: flex;
		flex-direction: column;

		.bb {
			// border: 1px solid red;
			margin-top: 180rpx;
			height: 100vh;
		}
		.aa {
			display: flex;
			justify-content: center;
			align-items: center;
			// border: 1px solid red;
			font-size: 20px;
			margin-top: 180rpx;
			height: 100vh;
		}
		.bt {
			display: flex;
			flex-direction: column;
			// align-items: start;
			// border: 1px solid darkblue;
		}

		.scroll-Y {
			height: 69vh;
			// border: 1px solid fuchsia;
		}

		.b1 {
			z-index: 1;
			height: 180rpx;
			display: flex;
			// border: 1px solid darkblue;
			align-items: center;
			justify-content: space-around;

			position: fixed;
			left: 0;
			right: 0;
			top: 20;
			background-color: white;

			.b1_zz {
				color: #a1a1a1;
				font-size: 25rpx;
				margin-left: 30rpx;
			}

			.b1_1 {
				// border: 1px solid darkblue;
				width: 300rpx;
				height: 80rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				margin-left: 0rpx;
				margin-top: 30rpx;
			}


			button::after {
				border: none; //去除边框
			}

			.b1_2_1 {
				margin-top: 40rpx;
				font-size: 25rpx;
				height: 60rpx;
				width: 140rpx;
				// background: rgba(255, 135, 137, 0.0); //设置背景色
				background-color: #15B54A;
				background: rgba(136, 217, 123, 0.3);
				color: #27c986
			}

			.b1_3_1 {
				margin-top: 40rpx;
				font-size: 25rpx;
				height: 60rpx;
				width: 140rpx;
				background-color: #15B54A;
				background: rgba(255, 0, 0, 0.3);
				color: #FF0000
			}
		}

		.b2 {
			font-size: 25rpx;
			width: 93%;
			height: 200rpx;
			background-color: white;
			margin-top: 40rpx;
			margin-left: 20rpx;
			display: flex;
			justify-content: space-between;
			border: 1px solid #56b6ec;
			box-shadow: 8px 5px 5px rgba(117, 160, 208, 0.3);

			.b2_1 {
				margin-left: 10rpx;
				// border: 1px solid darkcyan;
				display: flex;
				flex-direction: column;
				justify-content: space-around
			}

			.b2_2 {
				display: flex;
				flex-direction: column;
				justify-content: space-around;
				align-items: center;
				// border: 1px solid darkcyan;
				margin-right: 10rpx;
				width: 250rpx;

				.tt {
					border: 1px solid red;
					width: 100rpx;
					height: 40rpx;
					font-size: 10rpx;
				}

				.ee {
					display: flex;
					justify-content: center;
					align-items: center;
					border-radius: 15rpx;
					width: 100rpx;
					height: 25px;
					align-items: center;
					background: rgba(255, 0, 0, 0.3);
					color: #FF0000;
					// margin-left: 40rpx;


				}

				.ss {
					display: flex;
					justify-content: center;
					align-items: center;
					border-radius: 15rpx;
					width: 100rpx;
					height: 25px;
					align-items: center;
					color: #27c986;
					background: rgba(136, 217, 123, 0.3);
				}
			}

		}

	}
</style>